﻿using CoreLibrary.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace CoreLibrary.People
{
    public class Person
    {
        public Person()
        {
            LikeNotLike = new LikeNotLike();
            Bonds = new Dictionary<string, Bond>();
        }

        public LikeNotLike LikeNotLike { get; private set; }

        public virtual string Name { get; set; }

        public void AquireItem(Item item)
        {
            itemList.Add(item);
        }

        public void GiveItem(Person giveToPerson, Item item)
        {
            Bonds[giveToPerson.Name].BondStrength += TierLevelHelper.GetTierValue(giveToPerson.LikeNotLike.EvaluateItem(item));
            giveToPerson.AquireItem(item);
            itemList.Remove(item);
        }

        private List<Item> itemList = new List<Item>();
        public IEnumerable<Item> ItemList
        {
            get
            {
                return ItemList;
            }
        }

        public virtual PersonHairColor HairColor { get; set; }

        public virtual PersonHeight Height { get; set; }

        public virtual PersonSex Sex { get; set; }

        public virtual PersonBuild Build { get; set; }

        public Dictionary<string, Bond> Bonds { get; private set; }

        public void SetBond(Person p2, Bond b)
        {
            if (!Bonds.ContainsKey(p2.Name))
            {
                b.BondStrength += LikeNotLike.EvaluatePersonBond(p2);
                Bonds.Add(p2.Name, b);
            }

            if (!p2.Bonds.ContainsKey(Name))
            {
                b.BondStrength += p2.LikeNotLike.EvaluatePersonBond(this);
                p2.Bonds.Add(Name, b);
            }
        }

        public static IEnumerable<Type> GetPersonEnumTypes()
        {
            return Assembly.GetExecutingAssembly()
                    .GetTypes()
                    .Where(t => t.IsEnum && t.IsPublic && t.Name.StartsWith("Person"));

        }
    }
}